package model;

import java.sql.Date;

/**
 * A POJO that represents one row in the history table.
 * @author Lawrence Grass
 */
public class HistoryItem {
	
	/**
	 * The name of the item
	 */
	private String item;
	
	/**
	 * The cost per each item
	 */
	private int qty;
	
	/**
	 * Is it on sale?
	 */
	private Date lastPurchased;
	
	/**
	 * Constructs a POJO representation of an item
	 * @param item name
	 * @param price of the item
	 * @param sale if it's on sale
	 */
	public HistoryItem(String item, int qty, Date lastPurchased){
		this.item = item;
		this.qty = qty;
		this.lastPurchased = lastPurchased;
	}
	
	/**
	 * @return the item name
	 */
	public String getItem(){
		return item;
	}
	
	/**
	 * @return the item price
	 */
	public int getQuantity(){
		return qty;
	}
	
	/**
	 * @return the date this was purchased
	 */
	public Date getLastPurchased(){
		return lastPurchased;
	}
	
	public String toString(){
		return "History Item: " + item + ", Quantity: " + qty + ", Purchase date: " + lastPurchased;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((item == null) ? 0 : item.hashCode());
		result = prime * result
				+ ((lastPurchased == null) ? 0 : lastPurchased.hashCode());
		result = prime * result + qty;
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		HistoryItem other = (HistoryItem) obj;
		if (item == null) {
			if (other.item != null)
				return false;
		} else if (!item.equals(other.item))
			return false;
		if (lastPurchased == null) {
			if (other.lastPurchased != null)
				return false;
		} else if (!lastPurchased.equals(other.lastPurchased))
			return false;
		if (qty != other.qty)
			return false;
		return true;
	}
}
